wayland: Add some dumb support for the TARGETS selection
authorJasper St. Pierre <jstpierre@mecheye.net>
Thu, 3 Jul 2014 17:20:38 +0000 (13:20 -0400)
committerJasper St. Pierre <jstpierre@mecheye.net>
Thu, 3 Jul 2014 17:29:14 +0000 (13:29 -0400)
The way that GtkTextView et al pop up their context menu is to first
query to see if the clipboard has some text, and if so, enable the Paste
menu item. But since the Wayland backend hasn't had the greatest
selection and clipboard code, the callback for the clipboard got dropped
on the floor.

Add some simple code to respond to the TARGETS selection.

This makes right-clicking on a GtkTextView work fine.

gdk/wayland/gdkdevice-wayland.c
gtk/gtkclipboard-wayland.c

index 9471d31b5bcfd836d4d2749005a2458fb98804fd..0da19a68e85f47e13fc15419975859037ecd4c9e 100644 (file)
@@ -1770,6 +1770,15 @@ _gdk_wayland_device_get_button_press_serial (GdkWaylandDeviceData *device)
   return device->button_press_serial;
 }
 
+static GdkAtom
+mime_type_to_gdk_atom (char *mime_type)
+{
+  if (strcmp (mime_type, "text/plain;charset=utf8"))
+    return gdk_atom_intern_static_string ("UTF8_STRING");
+
+  return GDK_NONE;
+}
+
 gint
 gdk_wayland_device_get_selection_type_atoms (GdkDevice  *gdk_device,
                                              GdkAtom   **atoms_out)
@@ -1793,13 +1802,7 @@ gdk_wayland_device_get_selection_type_atoms (GdkDevice  *gdk_device,
 
   /* Convert list of targets to atoms */
   for (i = 0; i < device->selection_offer->types->len; i++)
-    {
-      atoms[i] = gdk_atom_intern (device->selection_offer->types->pdata[i],
-                                  FALSE);
-      GDK_NOTE (MISC,
-                g_message (G_STRLOC ": Adding atom for %s",
-                           (char *)device->selection_offer->types->pdata[i]));
-    }
+    atoms[i] = mime_type_to_gdk_atom (device->selection_offer->types->pdata[i]);
 
   *atoms_out = atoms;
   return device->selection_offer->types->len;
index 328ba4df417cc9b68a158914be3c17d5075b54bd..9e728025d0fc672856d33c2a96547b440999a461 100644 (file)
@@ -283,6 +283,24 @@ gtk_clipboard_wayland_request_contents (GtkClipboard            *gtkclipboard,
   device_manager = gdk_display_get_device_manager (gdk_display_get_default ());
   device = gdk_device_manager_get_client_pointer (device_manager);
 
+  if (target == gdk_atom_intern_static_string ("TARGETS"))
+    {
+      GtkSelectionData selection_data;
+      int n_atoms;
+      GdkAtom *atoms;
+
+      selection_data.selection = GDK_NONE;
+      selection_data.format = 32;
+      selection_data.type = GDK_SELECTION_TYPE_ATOM;
+
+      n_atoms = gdk_wayland_device_get_selection_type_atoms (device, &atoms);
+      selection_data.length = n_atoms;
+      selection_data.data = atoms;
+
+      callback (gtkclipboard, &selection_data, user_data);
+      return;
+    }
+
   /* When GTK+ requests text, it tries UTF8_STRING first and then
    * falls back to COMPOUND_TEXT and then STRING.  We rewrite
    * UTF8_STRING to text/plain;charset=utf-8, and if that doesn't